﻿using System.ComponentModel;
using System.Drawing;
using System.Runtime.CompilerServices;

namespace _34_C_中的枚举
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.Title = "C#中的枚举";

            //Console.WriteLine(Color.Red);

            //int red = (int)Color.Red;
            //Console.WriteLine(red);

            //Color color = (Color)2;
            //Console.WriteLine(color);

            //Color color;
            //Enum.TryParse( "Red",out color);
            //Console.WriteLine(color);

            //Color color = (Color)Enum.Parse(typeof(Color), "Red");
            //Console.WriteLine(color);

            //string str = Enum.GetName(typeof(Color),Color.Green);
            //Console.WriteLine(str);

            //Color color = (Color)8;//如果没有直接输出数值
            //Console.WriteLine(color);
            //Console.WriteLine(Enum.IsDefined(typeof(Color),color));

            //Color color = Color.Red;
            //Console.WriteLine($"{color:G}");//值
            //Console.WriteLine($"{color:D}");//int

            //Type type = Color.Blue.GetType();
            //Type type1=Enum.GetUnderlyingType(type);
            //Console.WriteLine(type);
            //Console.WriteLine(type1);

            //Array arry = Enum.GetValues(typeof(Color));
            //foreach (Color color in arry)
            //{
            //    Console.WriteLine(color);
            //}

            //string[] strings=Enum.GetNames(typeof(Color));

            //foreach (string s in strings)
            //{
            //    Console.WriteLine(s);
            //}


            //var filed = Color.Red.GetType().GetField(Color.Red.ToString());
            //var attr = Attribute.GetCustomAttribute(filed, typeof(DescriptionAttribute)) as DescriptionAttribute;
            //if (attr != null)
            //{
            //    Console.WriteLine(attr.Description);
            //}

            //& 如果同时存在于两个操作数中，二进制 AND 运算符复制一位到结果中。
            //| 如果存在于任一操作数中，二进制 OR 运算符复制一位到结果中。

            //位枚举
            var temp = Permission.read | Permission.add;

            Console.WriteLine(temp);

            if ((temp & Permission.update) != 0)
            {
                Console.WriteLine("有更新权限");
            }
            else
            {
                Console.WriteLine("没有更新权限");
            }

            Console.ReadKey();
        }
    }
}
